package com.example.demo.Control;

import com.example.demo.Common.AjaxResult;
import com.example.demo.Common.Session;
import com.example.demo.Entity.Friend;
import com.example.demo.Entity.Userinfo;
import com.example.demo.Service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendControl {
    @Autowired
    public FriendService friendService;
    @RequestMapping("/getList")
    public AjaxResult selectAll(HttpServletRequest req){
        HttpSession session= req.getSession(false);
        if(session==null){
            return AjaxResult.fail(-1,"参数缺失");
        }
        Userinfo userinfo=(Userinfo) session.getAttribute(Session.SEESSINO_KEY);
        if(userinfo==null){
            return AjaxResult.fail(-1,"当前用户不存在");
        }
        List<Friend> list=new ArrayList<>();
        list=friendService.selectAll(userinfo.getUserid());
        return AjaxResult.success(list);
    }
}
